package com.dkd.manage.service.Impl;

import com.dkd.manage.mapper.NodeMapper;
import com.dkd.manage.mapper.PolicyMapper;
import com.dkd.manage.pojo.dto.PolicyQueryListDto;
import com.dkd.manage.pojo.entity.Policy;
import com.dkd.manage.result.PageResult;
import com.dkd.manage.service.PolicyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class PolicyServiceImpl implements PolicyService {


    @Autowired
    private PolicyMapper policyMapper;
    @Autowired
    private NodeMapper nodeMapper;


    /**
     * 分页查询策略列表
     * @param policyQueryListDto
     * @return
     */
    @Override
    public PageResult<Policy> list(PolicyQueryListDto policyQueryListDto) {
        //开启分页
        PageHelper.startPage(policyQueryListDto.getPageNum(), policyQueryListDto.getPageSize());
        //查询区域列表
        List<Policy> policyList = policyMapper.list(policyQueryListDto);
        //创建分页详情对象
        PageInfo<Policy> pageInfo = new PageInfo<>(policyList);
        //封装数据返回
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
    }

    /**
     * 新增策略
     * @param policy
     */
    @Override
    public Integer add(Policy policy) {
        return policyMapper.add(policy);
    }

    /**
     * 修改策略
     * @param policy
     * @return
     */
    @Override
    public Integer edit(Policy policy) {
        return policyMapper.edit(policy);
    }

    /**
     * 根据id查询策略
     * @param id
     * @return
     */
    @Override
    public Policy getPolicyById(Long id) {
        return policyMapper.getPolicyById(id);
    }

    /**
     * 根据id删除策略
     * deleteRegionById
     * @param ids
     * @return
     */
    @Override
    public Integer deletePolicyById(Long[] ids) {
        return policyMapper.deletePolicyById(ids);
    }
}
